package com.bicon.botu.mall.order.controller;


import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.order.common.OrderConstans;
import com.bicon.botu.mall.order.entity.OrderAddress;
import com.bicon.botu.mall.order.service.IOrderAddressService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 个人收货地址 后台控制器
 * @author dsp
 * @since 2018-05-14
 */
@RestController
@RequestMapping(value = "/V3.0.0/orderAddress")
public class OrderAddressControllerV3 extends BaseController {

  @Autowired
  private IOrderAddressService iOrderAddressService;

  /**
   * 保存个人订单地址
   * @param orderAddress 订单地址对象
   * @return
   */
  @RequestMapping(value="save",method = RequestMethod.POST)
  public BaseResult save(OrderAddress orderAddress){
      //个人订单参数校验
      if(orderAddress != null && StringUtils.isNoneBlank(orderAddress.getUserId()
              ,orderAddress.getName(),orderAddress.getTelephone())){
        orderAddress.preInsert();
        boolean result=iOrderAddressService.insert(orderAddress);
        if(result){
          return sendResult200();
        }else{
          return sendResult(OrderConstans.RESPONSE_CODE_600,OrderConstans.RESPONSE_MESSAGE_600);
        }
      }else{
        return sendResult400();
      }
  }

  /**
   * 修改个人订单地址
   * @param orderAddress 订单地址对象
   * @return
   */
  @RequestMapping(value="update",method = RequestMethod.POST)
  public BaseResult update(OrderAddress orderAddress){
    //个人订单参数校验
    if(orderAddress != null && StringUtils.isNoneBlank(orderAddress.getId(),orderAddress.getUserId()
            ,orderAddress.getName(),orderAddress.getTelephone())){
      orderAddress.preInsert();
      boolean result=iOrderAddressService.updateById(orderAddress);
      if(result){

        return sendResult200();
      }else{
        return sendResult(OrderConstans.RESPONSE_CODE_600,OrderConstans.RESPONSE_MESSAGE_600);
      }
    }else{
      return sendResult400();
    }
  }

}
